package lance.honeydew.dao;

import lance.honeydew.bean.OrderDetail;
import lance.honeydew.bean.OrderInformation;

import org.apache.log4j.Logger;
import org.hibernate.Session;

public class OrderDetailDAO extends RootDAO {
	
	private static final Logger logger = Logger.getLogger(OrderDetailDAO.class);
	
	/**
	 * findOrderDetailBySeqId
	 * @param seqId
	 * @return
	 */
	public OrderDetail findOrderDetailBySeqId(Long seqId) {
		
		OrderDetail result = null;
		try {
			
			if (seqId != null) {
				String sqlString = " select od from OrderDetail od " +
						" inner join fetch od.Orderinformationseqid o " +
						" inner join fetch o.Userid u  " +
						" inner join fetch o.Paymentmethodseqid p  " + 
						" inner join fetch o.Transportmethodseqid t  " + 
						" inner join fetch od.Iteminformationseqid i  " + 
						" inner join fetch i.Categorybigseqid b  " +
						" inner join fetch i.Categorymedium m  " + 
						" where 1=1 ";
				
				sqlString += " and od.Seqid = " + seqId + " ";
				
				Session session = getSession();
				result = (OrderDetail) session.createQuery(sqlString).list().get(0);
				session.close();
			}
			
		} catch(Exception e) {
			e.printStackTrace();
			logger.debug(e);
		}
		
		return result;
	}
}